﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:LOAN_RETURNDETAIL
	/// </summary>
	public partial class LOAN_RETURNDETAIL : BaseDAL<GSLMS.Entity.TB_LOAN_RETURNDETAIL>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public LOAN_RETURNDETAIL()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_LOAN_RETURNDETAIL model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_RETURNID", model.RETURNID),
								new OracleParameter("P_SHOULDPAYDATE", model.SHOULDPAYDATE),
								new OracleParameter("P_SHOULDMAXPAYDATE", model.SHOULDMAXPAYDATE),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_SHOULDPHASE", model.SHOULDPHASE),
								new OracleParameter("P_SHOULDCAPITAL", model.SHOULDCAPITAL),
								new OracleParameter("P_SHOULDINT", model.SHOULDINT),
								new OracleParameter("P_SHOULDCOST", model.SHOULDCOST),
								new OracleParameter("P_SHOULDFEES", model.SHOULDFEES),
								new OracleParameter("P_SHOULDDELAYINT", model.SHOULDDELAYINT),
								new OracleParameter("P_SHOULDDELAYAMT", model.SHOULDDELAYAMT),
								new OracleParameter("P_TOTALSHOULD", model.TOTALSHOULD),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDCOST", model.REDCOST),
								new OracleParameter("P_REDFEES", model.REDFEES),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_TOTALRED", model.TOTALRED),
								new OracleParameter("P_RETURNSTATUS", model.RETURNSTATUS),
								new OracleParameter("P_STATUS", model.STATUS)};
  
			for (int i = 0; i < 25; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_returndetail_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_LOAN_RETURNDETAIL model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_RETURNID", model.RETURNID),
								new OracleParameter("P_SHOULDPAYDATE", model.SHOULDPAYDATE),
								new OracleParameter("P_SHOULDMAXPAYDATE", model.SHOULDMAXPAYDATE),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_SHOULDPHASE", model.SHOULDPHASE),
								new OracleParameter("P_SHOULDCAPITAL", model.SHOULDCAPITAL),
								new OracleParameter("P_SHOULDINT", model.SHOULDINT),
								new OracleParameter("P_SHOULDCOST", model.SHOULDCOST),
								new OracleParameter("P_SHOULDFEES", model.SHOULDFEES),
								new OracleParameter("P_SHOULDDELAYINT", model.SHOULDDELAYINT),
								new OracleParameter("P_SHOULDDELAYAMT", model.SHOULDDELAYAMT),
								new OracleParameter("P_TOTALSHOULD", model.TOTALSHOULD),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDCOST", model.REDCOST),
								new OracleParameter("P_REDFEES", model.REDFEES),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_TOTALRED", model.TOTALRED),
								new OracleParameter("P_RETURNSTATUS", model.RETURNSTATUS),
								new OracleParameter("P_STATUS", model.STATUS)};
  
			for (int i = 0; i < 25; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_returndetail_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_returndetail_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_LOAN_RETURNDETAIL DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_LOAN_RETURNDETAIL model = new GSLMS.Entity.TB_LOAN_RETURNDETAIL();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["RETURNID"]!=null && dr["RETURNID"].ToString()!="")
				{
					model.RETURNID=OracleHelper.ToLong(dr["RETURNID"].ToString());
				}
				if(dr["SHOULDPAYDATE"]!=null && dr["SHOULDPAYDATE"].ToString()!="")
				{
					model.SHOULDPAYDATE=DateTime.Parse(dr["SHOULDPAYDATE"].ToString());
				}
				if(dr["SHOULDMAXPAYDATE"]!=null && dr["SHOULDMAXPAYDATE"].ToString()!="")
				{
					model.SHOULDMAXPAYDATE=DateTime.Parse(dr["SHOULDMAXPAYDATE"].ToString());
				}
				if(dr["PAYDATE"]!=null && dr["PAYDATE"].ToString()!="")
				{
					model.PAYDATE=DateTime.Parse(dr["PAYDATE"].ToString());
				}
				if(dr["SHOULDPHASE"]!=null && dr["SHOULDPHASE"].ToString()!="")
				{
                    model.SHOULDPHASE = OracleHelper.ToInt(dr["SHOULDPHASE"].ToString());
				}
				if(dr["SHOULDCAPITAL"]!=null && dr["SHOULDCAPITAL"].ToString()!="")
				{
					model.SHOULDCAPITAL=OracleHelper.ToDecimal(dr["SHOULDCAPITAL"].ToString());
				}
				if(dr["SHOULDINT"]!=null && dr["SHOULDINT"].ToString()!="")
				{
					model.SHOULDINT=OracleHelper.ToDecimal(dr["SHOULDINT"].ToString());
				}
				if(dr["SHOULDCOST"]!=null && dr["SHOULDCOST"].ToString()!="")
				{
					model.SHOULDCOST=OracleHelper.ToDecimal(dr["SHOULDCOST"].ToString());
				}
				if(dr["SHOULDFEES"]!=null && dr["SHOULDFEES"].ToString()!="")
				{
					model.SHOULDFEES=OracleHelper.ToDecimal(dr["SHOULDFEES"].ToString());
				}
				if(dr["SHOULDDELAYINT"]!=null && dr["SHOULDDELAYINT"].ToString()!="")
				{
					model.SHOULDDELAYINT=OracleHelper.ToDecimal(dr["SHOULDDELAYINT"].ToString());
				}
				if(dr["SHOULDDELAYAMT"]!=null && dr["SHOULDDELAYAMT"].ToString()!="")
				{
					model.SHOULDDELAYAMT=OracleHelper.ToDecimal(dr["SHOULDDELAYAMT"].ToString());
				}
				if(dr["TOTALSHOULD"]!=null && dr["TOTALSHOULD"].ToString()!="")
				{
					model.TOTALSHOULD=OracleHelper.ToDecimal(dr["TOTALSHOULD"].ToString());
				}
				if(dr["REDCAPITAL"]!=null && dr["REDCAPITAL"].ToString()!="")
				{
					model.REDCAPITAL=OracleHelper.ToDecimal(dr["REDCAPITAL"].ToString());
				}
				if(dr["REDINT"]!=null && dr["REDINT"].ToString()!="")
				{
					model.REDINT=OracleHelper.ToDecimal(dr["REDINT"].ToString());
				}
				if(dr["REDCOST"]!=null && dr["REDCOST"].ToString()!="")
				{
					model.REDCOST=OracleHelper.ToDecimal(dr["REDCOST"].ToString());
				}
				if(dr["REDFEES"]!=null && dr["REDFEES"].ToString()!="")
				{
					model.REDFEES=OracleHelper.ToDecimal(dr["REDFEES"].ToString());
				}
				if(dr["REDDELAYINT"]!=null && dr["REDDELAYINT"].ToString()!="")
				{
					model.REDDELAYINT=OracleHelper.ToDecimal(dr["REDDELAYINT"].ToString());
				}
				if(dr["REDDELAYAMT"]!=null && dr["REDDELAYAMT"].ToString()!="")
				{
					model.REDDELAYAMT=OracleHelper.ToDecimal(dr["REDDELAYAMT"].ToString());
				}
				if(dr["TOTALRED"]!=null && dr["TOTALRED"].ToString()!="")
				{
					model.TOTALRED=OracleHelper.ToDecimal(dr["TOTALRED"].ToString());
				}
				if(dr["RETURNSTATUS"]!=null && dr["RETURNSTATUS"].ToString()!="")
				{
                    model.RETURNSTATUS = OracleHelper.ToInt(dr["RETURNSTATUS"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_LOAN_RETURNDETAIL GetByID(long ID)
		{
			GSLMS.Entity.TB_LOAN_RETURNDETAIL sModel = new GSLMS.Entity.TB_LOAN_RETURNDETAIL();
			string sql = "";
			sql = "select * from TB_LOAN_RETURNDETAIL where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_LOAN_RETURNDETAIL> GetList(GSLMS.Entity.TB_LOAN_RETURNDETAIL searchParam)
		{
			var list=new List<GSLMS.Entity.TB_LOAN_RETURNDETAIL>();
			DataTable dt = null;
			string tblName = "TB_LOAN_RETURNDETAIL";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_LOAN_RETURNDETAIL model = new GSLMS.Entity.TB_LOAN_RETURNDETAIL();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

